package com.etc.service.impl;
import com.etc.entity.User;
import com.etc.service.UserService;
import com.etc.user.dao.UserMapper;
import com.etc.util.PageData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper usermaper;

    @Override
    public User getUserById(int userid) {
        return usermaper.selectByPrimaryKey(userid);
    }

    @Override
    //read=true设置只读，就不能进行增删改，只能查
    public boolean addUser(User user) {
        int n=usermaper.insert(user);
        return n>0;
    }
    /**
     * 分页
     */
    @Override
    public PageData<User> getUsersByPage(int page, int pageSize, String content) {
        int start=(page-1)*pageSize;
        List<User> data=usermaper.getUserByPage(start, pageSize, content);
        int count=usermaper.getTotal(content);
        PageData<User> pd=new PageData<>(data, count, pageSize, page);
        return pd;
    }



    @Override
    public boolean delUsers(int userid) {
        // TODO Auto-generated method stub
        return usermaper.deleteByPrimaryKey(userid)>0;
    }

    @Override
    public boolean update(User user) {
        // TODO Auto-generated method stub
        return usermaper.updateByPrimaryKey(user)>0;
    }
}
